<template>
  <a-modal
    :visible="visible"
    :confirmLoading="isSubmiting"
    :afterClose="hanldeAfterClose"
    @cancel="close"
    @ok="handleSubmit"
    :title="title"
  >
    <a-form :form="form">
      <a-form-item :label="label">
        <a-textarea
          v-decorator="['Remark', { rules: [{ required: remarkRequired, message: `请输入${label}` }] }]"
          :placeholder="`请输入${label}`"
          :auto-size="{ minRows: 3, maxRows: 5 }"
        ></a-textarea>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import { postExitHouses } from '@/api/followUpManagement'
export default {
  props: {
    title: {
      type: String,
      default: '',
    },
    visible: {
      type: Boolean,
      default: false,
    },
    data: {
      type: Object,
      default: () => {},
    },
    mode: {
      type: String,
      required: true,
      default: '',
    },
    filedName: {
      type: Object,
      default: () => {
        return {
          HouseID: 'ESites',
          ProposerID: 'ID',
        }
      },
    },
    remarkRequired: {
      type: Boolean,
      default: false,
    },
    label: {
      type: String,
      default: '备注',
    },
  },
  data() {
    return {
      form: this.$form.createForm(this, { name: 'followUpModal' }),
      isSubmiting: false,
    }
  },
  methods: {
    close() {
      this.form.resetFields()
      this.$emit('update:visible', false)
      this.$emit('update:data', {})
    },
    handleSubmit() {
      this.form.validateFields((err, values) => {
        if (!err) {
          this.isSubmiting = true
          const { HouseID, ProposerID } = this.filedName
          postExitHouses({
            Mode: this.mode,
            UserID: this.$store.getters.userid,
            HouseID: this.data[HouseID],
            ProposerID: this.data[ProposerID],
            Remark: values.Remark,
            UserName: this.$store.getters.nickname,
          })
            .then((res) => {
              if (res.code == 201) {
                this.$message.error(res.msg)
                this.close()
              } else {
                this.$message.success(`${this.title}成功！`)
                this.$emit('success', false)
                this.close()
              }
            })
            .finally(() => {
              this.isSubmiting = false
            })
        }
      })
    },
    hanldeAfterClose() {},
  },
}
</script>
<style lang="less" scoped></style>
